/*
 * Created by JFormDesigner on Sun Jun 06 21:54:07 CST 2021
 */

package com.J1ay.carsys.gui.User;

import com.J1ay.carsys.gui.Welcome;
import com.J1ay.carsys.pojo.Bower;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author Brainrain
 */
public class UserMain extends JFrame {
    String numbers;
    Bower nowbower = new Bower();
    public UserMain() {
        initComponents();
    }
    public UserMain(Bower bower) {
        initComponents();
        System.out.println(bower.getPhone());
        this.label.setText(bower.getBname()+",欢迎您");
        this.numbers = bower.getPhone();
        this.nowbower = bower;
    }
    public void start() {
        this.setVisible(true);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    private void exitActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Welcome().start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void bowCarActionPerformed(ActionEvent e) {
        // TODO add your code here
        new BowCar(nowbower).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void huanCarActionPerformed(ActionEvent e) {
        // TODO add your code here
        new HuanCar(nowbower).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        bowCar = new JButton();
        huanCar = new JButton();
        label = new JLabel();
        exit = new JButton();

        //======== this ========
        setTitle("\u5c0f\u6c7d\u8f66\u51fa\u79df\u7ba1\u7406\u7cfb\u7edf");
        Container contentPane = getContentPane();

        //---- bowCar ----
        bowCar.setText("\u501f\u8f66");
        bowCar.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                bowCarActionPerformed(e);
            }
        });

        //---- huanCar ----
        huanCar.setText("\u8fd8\u8f66");
        huanCar.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                huanCarActionPerformed(e);
            }
        });

        //---- label ----
        label.setText("\u6b22\u8fce\u60a8,");

        //---- exit ----
        exit.setText("\u9000\u51fa");
        exit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exitActionPerformed(e);
            }
        });

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                            .addGap(0, 292, Short.MAX_VALUE)
                            .addComponent(exit))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGap(95, 95, 95)
                            .addComponent(bowCar)
                            .addGap(58, 58, 58)
                            .addComponent(huanCar)
                            .addGap(0, 69, Short.MAX_VALUE)))
                    .addContainerGap())
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addGap(0, 145, Short.MAX_VALUE)
                    .addComponent(label, GroupLayout.PREFERRED_SIZE, 114, GroupLayout.PREFERRED_SIZE)
                    .addGap(109, 109, 109))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(33, 33, 33)
                    .addComponent(label, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
                    .addGap(36, 36, 36)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(bowCar)
                        .addComponent(huanCar))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                    .addComponent(exit)
                    .addContainerGap())
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JButton bowCar;
    private JButton huanCar;
    private JLabel label;
    private JButton exit;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
